package pack08_covid_grouping;


import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author lilulu
 * @date 2023/2/11 14:23
 */
public class CovidGroupingReducer extends Reducer<CovidGroupingBean, Text,Text, NullWritable> {
    @Override
    protected void reduce(CovidGroupingBean key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        //1:从[v2]中获取第一个值，即为Top1
        /*Text next = values.iterator().next();
        context.write(next,NullWritable.get());*/

        //获取每个州的Top3
        int i = 0;
        for (Text value : values) {
            context.write(value, NullWritable.get());
            if (++i >= 3) {
                break;
            }
        }
    }
}
